<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1">
  <title>Title</title>
  <style>
    h3 {
      border: 1px solid #999;
    }

    * {
      word-break: break-all;
    }
  </style>
</head>

<body>
  <br>
  <h3 onclick="getUser()">用户信息</h3>
  <br>
  <div id="geturl"></div>
  <br>
  <div id="getCode"></div>
  <br>
  <div id="getUsers"></div>
  <script>
    function get(url, data, cb) {
      var xhr;
      if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
      } else {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      }

      xhr.onreadystatechange = () => {
        if (xhr.readyState === 4) {
          if (xhr.status === 200)
            cb(xhr.responseText);
          else
            cb(null);
        }
      };
      xhr.open('GET', url, true);
      xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      // xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=AaB03x');
      xhr.send(null);
    }
  </script>
  <script>
    window.onload = function () {
      document.getElementById('geturl').innerHTML = window.location.href;
      document.getElementById('getCode').innerHTML = urlParam('code');
      getUser();
    };
    function urlParam(name) {
      var rc = null;
      var val = `&${location.search.substr(1)}&`;
      var rg = new RegExp(`&${name}=([^&]*)&`);
      var rgs = rg.exec(val);
      if (rgs) {
        rc = rgs[1];
        rc = decodeURIComponent(rc);
      }

      return rc;
    }
    function getUser() {
      get('http://ws.nuoya.io/user/api/relTokens?sid=' + urlParam('sid')+'&code=' + urlParam('code'), '', function (rs) {
        if (rs) {
          var r = JSON.parse(rs);
          get('http://ws.nuoya.io/user/api/relandwx?token=' + r.token, '', function (res) {
            document.getElementById('getUsers').innerHTML = res;
          });
        }
      });
    }
  </script>
  <script src="vconsole.min.js"></script>
</body>

</html>